using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DirectoryPanel : IUIBehavior
{
    private InputField _ipf_find;
    private DirectoryList _directoryList;
    public override void Init()
    {
        _ipf_find = GetUIElement<InputField>("ipf_find");
        _directoryList = GetUIElement<ScrollRect>("scr_directoryList").GetComponent<DirectoryList>();
    }

    public override void AddListener()
    {
        UIController.CommandEvent.AddListener(DirectoryPanelEvent.Generate.ToString(), OnDirctoryGenerated);
        GetUIElement<Button>("btn_find").onClick.AddListener(OnFindClick);
    }

    public override void RemoveListener()
    {
        GetUIElement<Button>("btn_find").onClick.RemoveListener(OnFindClick);
    }

    public void OnDirctoryGenerated(params object[] messages)
    {
        List<DirectoryListInfo> directoryList = (List<DirectoryListInfo>)messages[0];
        _directoryList.Generate(directoryList);
        _directoryList.onDirectoryClick.AddListener((info, isOn, isCheckClick) =>
        {
            UIController.PanelEvent.Invoke(DirectoryPanelEvent.Find.ToString(), info, isOn, isCheckClick);
        });
    }

    public void OnFindClick()
    {
        _directoryList.FindDirectory(_ipf_find.text);
    }
}

public enum DirectoryPanelEvent
{
    Generate,
    Find,
}
